package com.sun.component;

import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sun.lib.AppConfig;
import com.sun.lib.LibCommonManager;
import com.sun.lib.service.IAppComponent;

/*
 * Created by Administrator on 2019/7/30.
 *
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */
public class MyApplication extends Application implements IAppComponent {
    private static MyApplication mApp;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;
        inital(this);
        LibCommonManager.getInstance().init(this);
    }

    @Override
    public void inital(Application application) {
        for (String path : AppConfig.COMPONENTS) {
            try {
                Class<?> clazz = Class.forName(path);
                Object object = clazz.newInstance();
                if (object instanceof IAppComponent)
                    ((IAppComponent) object).inital(application);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static Application getContext() {
        return mApp;
    }
}
